package com.example.controller;

import com.example.common.Result;
import com.example.entity.Foodtable;
import com.example.entity.Menu;
import com.example.entity.MenuOrder;
import com.example.entity.PageBean;
import com.example.service.MenuOrderService;
import com.example.service.impl.MenuServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/menu_order")
public class MenuOrderController {
    @Autowired
    private MenuOrderService menuOrderService;
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize, Integer orderid
    ) {
        PageBean pageBean = menuOrderService.page(page, pageSize, orderid);
        log.info("分页查询的参数：{}，{}，{}", page, pageSize, orderid);
        return Result.success(pageBean);
    }

    @PostMapping("/add")
    public Result add(@RequestBody MenuOrder menuOrder) throws ParseException {
        menuOrderService.add(menuOrder);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("order_id") String order_id,@RequestParam("menu_id") String menu_id) {
        menuOrderService.delete(order_id,menu_id);
        return Result.success();
    }
    @PutMapping("/updata")
    public Result updata(@RequestBody MenuOrder menuOrder){
        menuOrderService.updata(menuOrder);
        return Result.success();
    }
    @PostMapping("/save")
    public Result save(@RequestBody MenuOrder menuOrder) throws ParseException {
        menuOrderService.save(menuOrder);
        return Result.success();
    }
    @GetMapping("/info")
    public Result page(@RequestParam("order_id") Integer order_id) {
        List<MenuOrder> MenuOrderList = menuOrderService.MenuOrderByorderid(order_id);
        return Result.success(MenuOrderList);
    }
}
